package nl.ajonker.railroad.pl;

import nl.ajonker.railroad.dl.SwitchRail;
import nl.ajonker.railroad.ui.drawcommand.DrawCommand;

import java.awt.*;

public class RailView {
    public enum SwitchType {
        LEFT, RIGHT, DOUBLE
    }

    private final SwitchRail rail;
    private final Point position;
    private final int rotation;
    private final SwitchType type;
    private final DrawCommand drawCommand;

    public RailView(SwitchRail rail, DrawCommand drawCommand, Point position, SwitchType type, int rotation) {
        if (rail == null) {
            throw new NullPointerException("Rail is null");
        }
        this.rail = rail;
        this.drawCommand = drawCommand;
        this.position = position;
        this.rotation = rotation;
        this.type = type;
    }

    public RailView(SwitchRail rail, DrawCommand drawCommand, Point position, SwitchType type) {
        this(rail, drawCommand, position, type, 0);
    }

    public String getName() {
        return rail.getName();
    }

    public void draw(Graphics2D graphics2D, int dimension) {
        drawCommand.draw(graphics2D, this, dimension);
    }

    public Shape getRegion(int dimension) {
        return drawCommand.getRegion(this, dimension);
    }

    public Point getPosition() {
        return position;
    }

    public int getRotation() {
        return rotation;
    }

    public SwitchType getType() {
        return type;
    }

    public SwitchRail.SwitchState getSwitchState() {
        return rail.getSwitchState();
    }
}
